package com.yanqu.road.server.manager.activity.doublespring.pb;

import com.yanqu.road.entity.activity.doublespring.data.DoubleSpringUserData;
import com.yanqu.road.entity.player.UserBaseInfo;
import com.yanqu.road.logic.pb.PlayerBasePb;
import com.yanqu.road.pb.activity.DoubleSpringProto;
import com.yanqu.road.server.manager.user.CrossUserMgr;

public class CrossDoubleSpringActivityPb {

    /**
     * 构建 DoubleSpringPlayerData
     * @param userId
     * @param data
     * @param userBaseInfo
     * @return
     */
    public static DoubleSpringProto.DoubleSpringPlayerData.Builder buildDoubleSpringPlayerData(long userId, DoubleSpringUserData data, UserBaseInfo userBaseInfo) {
        DoubleSpringProto.DoubleSpringPlayerData.Builder builder = DoubleSpringProto.DoubleSpringPlayerData.newBuilder();
        //积分信息
        DoubleSpringProto.DoubleSpringPlayerScoreData.Builder scoreData = buildDoubleSpringPlayerScoreData(userId, data);
        builder.setScoreData(scoreData);
        //玩家基础信息
        if (userBaseInfo != null) {
            builder.setPlayerBaseData(PlayerBasePb.parsePlayerBaseTempMsg(userBaseInfo));
        }
        return builder;
    }

    /**
     * 构建 DoubleSpringPlayerScoreData
     * @param userId
     * @param data
     * @return
     */
    public static DoubleSpringProto.DoubleSpringPlayerScoreData.Builder buildDoubleSpringPlayerScoreData(long userId, DoubleSpringUserData data) {
        DoubleSpringProto.DoubleSpringPlayerScoreData.Builder builder = DoubleSpringProto.DoubleSpringPlayerScoreData.newBuilder();
        builder.setUserId(userId);
        if (data == null) {
            builder.setScore(0);
            builder.setTotalScore(0);
            builder.setOutingFlag(false);
        } else {
            builder.setScore(data.getScore());
            builder.setTotalScore(data.getTotalScore());
            builder.setOutingFlag(data.getPartnerUserId() > 0);
        }
        return builder;
    }
}
